package com.gzpi.hwgggh.controller;

import com.gzpi.hwgggh.service.DWFJService;
import com.gzpi.hwgggh.sysenum.EnumErrorCode;
import com.gzpi.hwgggh.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @date : 2021-01-21 19:55
 **/
@RestController
@RequestMapping("DWFJ")
@CrossOrigin
public class DWFJController {

    @Autowired
    private DWFJService dwfjService;

    /**
     * 获取附件信息
     * @param dwbh 点位编号
     * @return
     */
    @RequestMapping(value = "/getDWFJByDWBH.do")
    public Result getDWFJByDWBH(String dwxid){
        try {
            return dwfjService.getDWFJByMap(dwxid);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.createError(EnumErrorCode.ERROR_SYSTEM_UNKNOWN.toString());
        }
    }

    /**
     * 编辑附件信息
     * @param files 附件文件
     * @param dwfjJson 附件json数据
     * @param szrgsJson 规划设置人json数据
     * @param szrxsJson 新增设置人json数据
     * @param request
     * @return
     */
    @RequestMapping(value = "/editDWFJ.do",method = RequestMethod.POST)
    public Result editDWFJ(@RequestParam(value = "dwfjFiles",required = false) MultipartFile[] files, String dwfjJson, HttpServletRequest request){
        try {
           return dwfjService.updateDWFJ(files,dwfjJson,request);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.createError(EnumErrorCode.ERROR_SYSTEM_UNKNOWN.toString());
        }
    }

}
